package com.david.jetpack.compose

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp

//参考链接：https://blog.csdn.net/guolin_blog/article/details/131622694?spm=1001.2014.3001.5501
//https://blog.csdn.net/guolin_blog/article/details/132253342?spm=1001.2014.3001.5501
class ComposeActivity: ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            messageCard()
        }
//        setcontent {
//            Text("haha")
//        }
    }

    @Preview
    @Composable
    fun messageCard(){
        var count by remember {
            mutableStateOf(0)
        }
        Row(modifier = Modifier
            .clickable {
                Log.e("test", "row is clicked")
                ++count
            }
            .background(Color.Blue)
            .width(Dp(150f))
            .height(Dp(150f)), horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.Bottom) {
            Box(modifier = Modifier
                .height(Dp(100f))
                .width(Dp(100f))
                .background(Color.White)) {
                Column(modifier = Modifier
                    .background(Color.Red)
                    .align(Alignment.Center), verticalArrangement = Arrangement.Bottom) {
                    Text("hello compose!!!")
                }

                Text(text = "hahah", modifier = Modifier
                    .align(Alignment.BottomCenter)
                    .padding(bottom = Dp(10f)))
            }
        }

    }

}